Created
November 10, 2013 20:03
-
-
Save abdullahbutt/7403165 to your computer and use it in GitHub Desktop.
CI db connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imagine you are writing a database query. This is how you might write a function within your PHP programme to query a MySQL database: | |
$connection = mysql_connect("localhost","fred","12345"); | |
mysql_select_db("websites", $connection); | |
$result = mysql_query ("SELECT * FROM sites", $connection); | |
while ($row = mysql_fetch_array($result, MYSQL_NUM)) | |
{ | |
foreach ($row as $attribute) | |
print "{$attribute[1]} "; | |
} | |
Now see how a CI function would handle a similar query: | |
$this->load->database('websites'); | |
$query = $this->db->get('sites'); | |
foreach ($query->result() as $row) | |
{ | |
print $row->url | |
} | |
Compare the character counts: 244 for the traditional syntax; 112 for CI. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment