Connect to MySQL

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Fri Nov 01, 2013 2:32 pm

Connect to MySQL

Postby krkeckukec » Fri Nov 01, 2013 2:39 pm

I am trying to connect to database and get int.
here is code:

Code: Select all

!DOCTYPE html>
    <link type='text/css' rel='stylesheet' href='style.css'/>
$mysqli= mysqli_connect("localhost","root","m62rm8F4","test");
if (mysqli_connect_errno($mysqli)) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
$res = mysqli_query($mysqli,"SELECT `KID` FROM `upis` WHERE (`Datum` = '" . $year . "-" . $month . "-" . $list_day. "')");
$row = $res->mysqli_fetch_array(MYSQLI_NUM);
$intnum = $row[0];
echo $intnum;


database has one table upis witch has these coumns: ID(int), Datum(Date); KID(INT)

when I open page i always get this:
mysqli_fetch_array(MYSQLI_NUM); $intnum = $row[0]; ?>
Please help

New php-forum User
New php-forum User
Posts: 4
Joined: Mon Nov 18, 2013 10:41 pm

Re: Connect to MySQL

Postby nanirao89 » Thu Nov 21, 2013 5:52 am

Please change the following line to below:
$row = $res->mysqli_fetch_array(MYSQLI_NUM);

$row = mysqli_fetch_array($res,MYSQLI_NUM);

Note: Follow object oriented type or normal . Don't use object method in normal way of calling.

Return to “PHP coding => General”

Who is online

Users browsing this forum: Google Adsense [Bot] and 2 guests