Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Connect to MySQL

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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>
<html>
  <head>
    <link type='text/css' rel='stylesheet' href='style.css'/>
    <title>PHP!</title>
  </head>
  <body> 
 
  <?php
 
$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;

  ?>
  </body>
</html>


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
krkeckukec
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Nov 01, 2013 2:32 pm

Re: Connect to MySQL

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

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

Modified:
$row = mysqli_fetch_array($res,MYSQLI_NUM);

Note: Follow object oriented type or normal . Don't use object method in normal way of calling.
nanirao89
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Nov 18, 2013 10:41 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron