Chapter 4 Pg 118-123 HELP!

Hi,

Following php & mysql SP book 4th edition.

Seems I cannot figure this out:

<?php
    
$link = mysqli_connect('127.0.0.1', 'root', 'thewordyoucannot4get=password');
    
	if (!$link)
		{
			$output = 'test to see MySQL server.';
			include 'output.html.php';
			exit();
		}	
    
	if (!mysql_set_charset(!$link, 'utf8'))
		{
			$output = 'test to see MySQL server.';
			include 'output.html.php';
			exit();
		} 
		
		if (!mysqli_select_db($link, 'ijdb'))
		{
			$output = 'test to see MySQL server.';
			include 'output.html.php';
			exit();
		}
				
			$output = 'test to see MySQL server.';
			include 'output.html.php';		
	
			mysqli_close($link);
	
		?>

This code produces the error: :smashy:

Warning: mysql_set_charset() [function.mysql-set-charset]: It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/Helsinki’ for ‘2.0/no DST’ instead in C:\Apache2\htdocs\php\learn\index.php on line 12

Warning: mysql_set_charset() expects parameter 2 to be resource, string given in C:\Apache2\htdocs\php\learn\index.php on line 12
test to see MySQL server.

Localhost
Apche 2.2.1.4
PHP: 5.3
MySQL: 5.1.42

enabled everything according to the book.

To avoid this warning either:

– Suppress warning messages by changing your error reporting level

– Do as the warning says, and edit your php.ini to specify the server’s time zone

– Do as the warning says, and call date_default_timezone_set

– Not call mysql_set_charset at all – set the character set in your MySQL configuration instead of in your PHP code

Also

    if (!mysql_set_charset(!$link, 'utf8'))

This line you copied wrong from the book, you don’t want the negation (!) of the link resource variable

Hope that helps

will try when I get home thanks Dan & let u kno if it works

Hi guys,
This warning (not an error) occurs because of a change in PHP 5.3 which came out after the book. It’s also mentioned on the errata page. It’s the one that begins “As of PHP 5.3, the date function requires that a timezone be specified.”

Hi,

Getting Warning now: Warning: mysql_set_charset() expects parameter 1 to be string, object given
Unable to Connect.
line 12

& have edited php.ini & included timezone

fixed :slight_smile:

oh! What was the solution?

Two typos were on that line – mysql_set_charset instead of mysqli_set_charset (which take parameters in opposite order resulting in that warning), and a negation operator (!) in front of $link.

silly me :frowning:

but thanks for help guys & the book is very well written & learning even if I make mistakes…