Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Tutorials
[PHP] How to use MySQLi
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="RastaLulz" data-source="post: 45927" data-attributes="member: 1"><p>MySQLi Info:</p><p><a href="http://php.net/manual/en/book.mysqli.php" target="_blank">http://php.net/manual/en/book.mysqli.php</a></p><p></p><p>Today I'll show you the basics of MySQLi, and how to use it. I'm showing you this because a lot of you still use the old mysql functions. That's bad because they really are outdated, less secure, and less efficient.</p><p></p><p>Connect to MySQL database:</p><p>[PHP]<?php</p><p>$_CONFIG['mysql']['host'] = 'localhost';</p><p>$_CONFIG['mysql']['user'] = 'root';</p><p>$_CONFIG['mysql']['pass'] = 'pass';</p><p>$_CONFIG['mysql']['db'] = 'db';</p><p></p><p>$db = new mysqli($_CONFIG['mysql']['host'], $_CONFIG['mysql']['user'], $_CONFIG['mysql']['pass'], $_CONFIG['mysql']['db']);[/PHP]</p><p></p><p>Execute a query:</p><p>[PHP]$username = 'RastaLulz';</p><p></p><p>//update info</p><p>$db->query("UPDATE users SET email = 'booty@lulz.com' WHERE name = '".$username."'");</p><p></p><p>//get info</p><p>$getUserInfo = $db->query("SELECT * FROM users WHERE name = '".$username."'");[/PHP]</p><p></p><p>Get data:</p><p>[PHP]if($getUserInfo->num_rows > 0) {</p><p> $userInfo = $getUserInfo->fetch_object();</p><p> echo $user."'s emails is <strong>".$userInfo->email.'</strong>!';</p><p>}else{</p><p> echo 'Sorry, but that username could not be found.';</p><p>}[/PHP]</p><p></p><p>Stop SQL injections:</p><p>[PHP]$pass = '123456'; $email = 'null@null.net'; $id = '21';</p><p></p><p>$secure = $db->prepare('UPDATE users SET password = ?, email = ? WHERE id = ?');</p><p>$secure->bind_param('ssi', $pass, $email, $id); //ssi stands for string, string, integer - based on the question marks</p><p>$secure->execute();[/PHP]</p><p></p><p>If you have any questions, feel free to ask below.</p></blockquote><p></p>
[QUOTE="RastaLulz, post: 45927, member: 1"] MySQLi Info: [URL]http://php.net/manual/en/book.mysqli.php[/URL] Today I'll show you the basics of MySQLi, and how to use it. I'm showing you this because a lot of you still use the old mysql functions. That's bad because they really are outdated, less secure, and less efficient. Connect to MySQL database: [PHP]<?php $_CONFIG['mysql']['host'] = 'localhost'; $_CONFIG['mysql']['user'] = 'root'; $_CONFIG['mysql']['pass'] = 'pass'; $_CONFIG['mysql']['db'] = 'db'; $db = new mysqli($_CONFIG['mysql']['host'], $_CONFIG['mysql']['user'], $_CONFIG['mysql']['pass'], $_CONFIG['mysql']['db']);[/PHP] Execute a query: [PHP]$username = 'RastaLulz'; //update info $db->query("UPDATE users SET email = 'booty@lulz.com' WHERE name = '".$username."'"); //get info $getUserInfo = $db->query("SELECT * FROM users WHERE name = '".$username."'");[/PHP] Get data: [PHP]if($getUserInfo->num_rows > 0) { $userInfo = $getUserInfo->fetch_object(); echo $user."'s emails is <strong>".$userInfo->email.'</strong>!'; }else{ echo 'Sorry, but that username could not be found.'; }[/PHP] Stop SQL injections: [PHP]$pass = '123456'; $email = 'null@null.net'; $id = '21'; $secure = $db->prepare('UPDATE users SET password = ?, email = ? WHERE id = ?'); $secure->bind_param('ssi', $pass, $email, $id); //ssi stands for string, string, integer - based on the question marks $secure->execute();[/PHP] If you have any questions, feel free to ask below. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Tutorials
[PHP] How to use MySQLi
Top