Custom Search

News World

Jun 6, 2011

PHP > DB Abstraction

1 #########################################
2 SAMPLE FOR DB Abtraction
3 #########################################
4
5 < ? php
6 require_once 'MyDB.php';
7 $db = MyDB::connect('odbc://user:pw@host/mydb');
8 $stmt = $mydb->prepare('SELECT * FROM remark');
9 $result = $mydb->execute($stmt);
10 while($row = $mydb->fetchrow($result)) {
11 while($row as $field => $value ) {
12 echo "$field: $value
\n";
13 }
14 }
15 $db->disconnect();
16 ? >

PHP > Using DATE_FORMAT

1 #########################################
2 SIMPLE SCRIPT FOR DATE FORMAT
3 #########################################
4
5 < ? php
6 mysql_connect('localhost');
7 mysql_select_db('foo');
8 $result = mysql_query(
9 "select id, email,
10 date_format(ts,'%W %M %D, %Y %r') as d
11 from users order by ts");
12 if($result) {
13 while($row = mysql_fetch_assoc($result)) {
14 echo "$row[id] - $row[email] - $row[d]
\n";
15 }
16 } else {
17 echo mysql_error();
18 }
19 ? >

Output:
mesakh - web.solusi@gmail.com - Tuesday June 5th, 2011 09:26:46 AM
abetnego - e_webmedia@yahoo.com - Tuesday June 5th, 2011 09:26:46 AM

Jun 5, 2011

PHP > SELECT Query

1 #########################################
2 SIMPLE SCRIPT FOR SELECT QUERY
3 #########################################
4
5 < ? php
6 mysql_connect('localhost');
6 mysql_select_db('foo');
6 $result = mysql_query("select * from users");
6 if(!$result) echo mysql_error();
6 else {
6 while($row = mysql_fetch_row($result)) {
6 echo "$row[0] - $row[1] - $row[2] - $row[3] - $row[4]
\n";
6 }
6 }
6 ? >

Output:
mesakh - u8EOdeOls9ERlew - Web Solusi - web.solusi@gmail.com - 7823198438933424
abetnego - 7dTRdsf4Dler4524 - Web Media - e_webmedia@yahoo.com - 7823198438933424

Jun 4, 2011

PHP > Insert Query

1 < ? php
2 function add_user($id, $pass, $name, $email) {
3 $result=mysql_query("insert into users values
4 ('$id',ENCRYPT('$pass'),'$name','$email',NULL)");
5 if($result) {
6 echo "Row inserted
";
7 } else {
8 echo mysql_error()."
";
9 }
10 }
11 mysql_connect('localhost');
12 mysql_select_db('foo');
13 add_user('mesakh','sober','Web Solusi','web.solusi@gmail.com');
14 add_user('abetnego','weber','Web Media','e_webmedia@yahoo.com');
15 ? >

Output:
Row insertedRow inserted

IT Conversations

Moneycontrol Latest News

Latest new pages on Computer Hope

Latest from Infoworld

Door Lock

Door Lock Import Top Door Lock from China Contact Quality Manufacturers Now