Problems with connection to mysql database by PHP

Hi. I’m totally new to this kind of things, but I bought a Kevin Yank Book about PHP/mysql and started to rock.

I was doing everything on my own, but this stuff is just too hard for a beginner.
I looked everywhere trying to solve it on my own, but sorry I must ask you.

I have problem with connection to my sql database.

Codes:

Index.php :

<?php
$link = mysqli_connect('localhost', 'root', 'xxxxxx');
if (!$link)
{
   $output = 'Nie mo&#380;na si&#281; po&#322;&#322;&#261;czy&#263; z serwerem bazy danych.';
   include 'output.html.php';
   exit();
}

if (!mysqli_set_charset($link, 'utf8'))
{
   $output = 'Nie mo&#380;na ustanowi&#263; kodowania dla po&#322;&#261;czenia z baz&#261; danych.';
   include 'output.html.php';
   exit();
}

if (!mysqli_select_db($link, 'ijdb'))
{
   $output = 'Nie znaleziono bazy danych ijdb.';
   include 'output.html.php';
   exit();
}

$output = 'Nawi&#261;zano po&#322;&#261;czenie z baz&#261; danych.';
include 'output.html.php';

?>

and output.html.php :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<HEAD>
  <TITLE>Dane wynikowe PHP</TITLE>
  <meta http-equiv="content-type" content="text/html: charset=utf-8"/>
</HEAD>
<BODY>
<P>
<?php echo $output; ?>

</P>
</BODY>

I think there are no errors in this code, but when I’m launching localhost/connect/index.php it’s just nothing on the Firefox and on the IE it looks like this: Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\Index.php on line 2 … it’s after 2 hours of thinking, first it was just error 500. Apache 2.2.16 is running, PHP 5.2.14 installed and mysql serwer on, checked it with Mysql administator.

Can someone help me?

//sorry for my English, I’m Polish but doing my best.

This is really one for the PHP forum, I think. But wait in case someone knows the answer.

It didn’t work on my test set-up either, but I got
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2003): Can’t connect to MySQL server on ‘localhost’ (10061) in … line2
Nie mozna sie pollaczyc z serwerem bazy danych.

(Unable to connect to the database server. - google says its polaczyc not pollaczyc)

However, when I included in the mysqli_connect(…) my database name and the port number 3307, and set the select_db to my database, I got
Nawiazano polaczenie z baza danych.

(I’m connected to the database.)

I don’t like the OO approach, so I can’t be sure why yours fails.

Try running phpinfo() and check that mysqli is listed as running or installed or whatever the word is.

narvany, run this script:

<?php phpinfo(); ?>

Look for “Loaded Configuration File” and open that file in Notepad. Look out in that file for two lines:

extension=php_mysqli.dll
extension=php_mysqli.dll

If either of them two lines have a ; in front of them then remove the ; and save the file. Then you’ll need to restart the server.

On Windows, when you install newer versions of PHP, you’re going to lack mysql_* functions.
The reason for this is because lib_mysql.dll isn’t being loaded as mysqli is considered as more secure and advanced interface towards mysql. So, mysql_ functions have been left out. You’ll need to copy lib_mysql.dll to your windows/system32 folder if I’m not mistaken and do the things SpacePhoenix mentioned. I might be wrong since it’s been a few years since I’ve done this, but a bit of googling might help.

Note: if you’re doing this on another OS, then I’m absolutely making a wrong guess so I apologize :slight_smile:

Big thanks to all of you, problem is solved. There was nothing wrong with code, it was something wrong with instalation of apache and php, probably mysql modules. Re-installing helped.