Skip to content

Commit a103a32

Browse files
committed
MySQL API approarch
1 parent 8e70ced commit a103a32

File tree

8 files changed

+134
-1
lines changed

8 files changed

+134
-1
lines changed

config/application.config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'Fmi',
3737
'Auth',
3838
'CsnBase', // This is also a library. Can be used without adding it as a module in composer.json: "autoload": {"psr-0": {"CsnBase\\": "vendor/coolcsn/csn-base/src/"}}
39-
),
39+
'CsnUser',
40+
),
4041
'module_listener_options' => array(
4142
'config_glob_paths' => array(
4243
'config/autoload/{,*.}{global,local}.php',

module/CsnUser/Module.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace CsnUser;
4+
5+
class module
6+
{
7+
public function getConfig()
8+
{
9+
return include __DIR__ . '/config/module.config.php';
10+
}
11+
12+
public function getAutoloaderConfig()
13+
{
14+
return array(
15+
'Zend\Loader\StandardAutoloader' => array(
16+
'namespaces' => array(
17+
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
18+
),
19+
),
20+
);
21+
}
22+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
return array(
3+
'controllers' => array(
4+
'invokables' => array(
5+
'CsnUser\Controller\User' => 'CsnUser\Controller\UserController',
6+
),
7+
),
8+
'router' => array(
9+
'routes' => array(
10+
'csn_user' => array(
11+
'type' => 'Literal',
12+
'options' => array(
13+
'route' => '/csn-user',
14+
'defaults' => array(
15+
'__NAMESPACE__' => 'CsnUser\Controller',
16+
'controller' => 'User',
17+
'action' => 'index',
18+
),
19+
),
20+
'may_terminate' => true,
21+
'child_routes' => array(
22+
'default' => array(
23+
'type' => 'Segment',
24+
'options' => array(
25+
'route' => '/[:controller[/:action[/:id]]]',
26+
'constraints' => array(
27+
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
28+
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
29+
'id' => '[0-9]*',
30+
),
31+
'defaults' => array(
32+
),
33+
),
34+
),
35+
),
36+
),
37+
),
38+
),
39+
'view_manager' => array(
40+
// 'template_map' => array(
41+
// 'layout/Auth' => __DIR__ . '/../view/layout/Auth.phtml',
42+
// ),
43+
'template_path_stack' => array(
44+
'csn_user' => __DIR__ . '/../view'
45+
),
46+
),
47+
);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
namespace CsnUser\Controller;
3+
4+
use Zend\Mvc\Controller\AbstractActionController;
5+
use Zend\View\Model\ViewModel;
6+
7+
class UserController extends AbstractActionController
8+
{
9+
// R - Retrieve
10+
public function indexAction()
11+
{
12+
// 1) Using MySQL API
13+
$link = mysql_connect('localhost', 'root', 'password');
14+
if (!$link) {
15+
die('Could not connect: ' . mysql_error());
16+
}
17+
echo 'Connected successfully';
18+
19+
20+
$sql = 'SELECT usr_id FROM fmi.users WHERE usr_id = 1';
21+
$result = mysql_query($sql, $link);
22+
23+
if (!$result) {
24+
echo "DB Error, could not query the database\n";
25+
echo 'MySQL Error: ' . mysql_error();
26+
exit;
27+
}
28+
29+
while ($row = mysql_fetch_assoc($result)) {
30+
echo $row['usr_id'];
31+
}
32+
33+
mysql_free_result($result);
34+
35+
mysql_close($link);
36+
37+
return new ViewModel();
38+
}
39+
40+
// C - Create
41+
public function createAction()
42+
{
43+
$link = mysql_connect('localhost', 'root', 'password');
44+
45+
return new ViewModel();
46+
}
47+
48+
// U - Update
49+
public function updateAction()
50+
{
51+
return new ViewModel();
52+
}
53+
54+
// D - Delete
55+
public function deleteAction()
56+
{
57+
return new ViewModel();
58+
}
59+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Create</h1>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Delete</h1>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Index = Retrieve</h1>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Update</h1>

0 commit comments

Comments
 (0)