Which is better, MySQL or MySQLi? And why? Which should I use?
I mean better not just in terms of performance, but any other relevant feature.
Which is better, MySQL or MySQLi? And why? Which should I use?
I mean better not just in terms of performance, but any other relevant feature.
You can use prepared statements with mysqli.
And there's also a function to store large (blob) data that the "old" mysql extension has not.
// php-mysql: no oo-interface
$mysqli = new mysqli('localhost', 'localonly', 'localonly');
if ($mysqli->connect_error) {
die($mysqli->connect_error);
}
// php-mysql: no prepared statements
$stmt = $mysqli->prepare("INSERT INTO foo (mydata) VALUES (?)");
$stmt->bind_param("b", $null);
// php-mysql: no function to send data in chunks
$fp = fopen("php://input", "r");
while (!feof($fp)) {
$chunk = fread($fp, 4096);
$stmt->send_long_data(0, $chunk);
}
$stmt->execute();
You'll want to create non conflicting aliases for the id columns;
SELECT u.*, s.*, u.id AS uid, s.id AS sid
FROM bands u
inner join statuses s on u.status_id = s.id
WHERE u.status_id = 1
ORDER BY u.band_name
Then you can pick them out as $row['uid']
and $row['sid']
and still access your other columns as usual. The conflicting id
column is also still there, just avoid using it.
<?php
$sql = new mysqli('127.0.0.1','root','Qwert12345','plot_io_db');
//echo $sql->query('Select * From players');
?>
It will work. Just remove port from localhost (127.0.0.1)
mysqli_connect("","username" ,"password","databasename");//Server name cannot be NULL
use loaclhost for server name(In Loacl)
<?php
$con = mysqli_connect("localhost","username" ,"password","databasename");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Or can use MySQLi Procedural
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$con = mysqli_connect($servername, $username, $password);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
EDIT 01
$servername = "localhost";
$username = "root";
$password = "";
If you have a look at MySQL Improved Extension Overview, it should tell you everything you need to know about the differences between the two.
The main useful features are: