MySQLi Info:
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:
Execute a query:
Get data:
Stop SQL injections:
If you have any questions, feel free to ask below.
You must be registered for see links
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']);
Execute a query:
PHP:
$username = 'RastaLulz';
//update info
$db->query("UPDATE users SET email = '[email protected]' WHERE name = '".$username."'");
//get info
$getUserInfo = $db->query("SELECT * FROM users WHERE name = '".$username."'");
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.';
}
Stop SQL injections:
PHP:
$pass = '123456'; $email = '[email protected]'; $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();
If you have any questions, feel free to ask below.
Last edited by a moderator: