I have a question. This is a simple piece of php that should show the number of rows in a table.
<?php
$link = mysql_connect("localhost", "root", "1234") or die("Couldn't connect");
mysql_select_db("regulas", $link);
$result = mysql_query("SELECT * FROM index", $link) or die("Couldn't finish query");
$num_rows = mysql_num_rows($result);
echo $num_rows;
?>
However, the page displays:
Couldn't connect
I'm using a xampp server on my own computer: localhost
What am i doing wrong?
Thx Jules
You must provide the password in,there is no defauls password in WAMP or XAAXMP try this :
<?php
$link = mysql_connect("localhost", "root","", "1234") or die("Couldn't connect");
mysql_select_db("regulas", $link);
$result = mysql_query("SELECT * FROM index", $link) or die("Couldn't finish query");
$num_rows = mysql_num_rows($result);
echo $num_rows;
?>
Read the manual here : http://php.net/manual/en/function.mysqli-connect.php
I changed mysql to mysqli and changed index to siteIndex
<?php
$link = mysqli_connect("localhost", "root", "102030!!", "regulas") or die("Couldn't connect");
$result = mysqli_query($link, "SELECT * FROM siteIndex") or die("Couldn't finish query"); $num_rows = mysqli_num_rows($result);
echo $num_rows;
?>