-
Notifications
You must be signed in to change notification settings - Fork 17
/
MySQL_Example.php
54 lines (43 loc) · 1.34 KB
/
MySQL_Example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Example usage of the object - This page should work
* on a mysql_* discontinued php version - You will
* need to update connection/database/table info
*
* @author Aziz S. Hussain <[email protected]>
* @copyright GPL license
* @license http://www.gnu.org/copyleft/gpl.html
* @link http://www.AzizSaleh.com
*/
// Include the definitions
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MySQL_Definitions.php');
// Include the object
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MySQL.php');
// Include the mysql_* functions
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MySQL_Functions.php');
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('unit_sql_v_1', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$sql = "SELECT * FROM unit_sql_table_1 WHERE field_id >= 1";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
echo '<pre>';
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}
echo '</pre>';
mysql_free_result($result);
mysql_close($link);