FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Parse error: syntax error, unexpected T_NEW





m-productions
i get the following error

Parse error: syntax error, unexpected T_NEW in /home/mproduct/domains/m-productions.frih.net/public_html/php/db_fns.php on line 7

Here is db_fns.php

Code:
<?php

function db_connect()
{
   $result = new mysqli('localhost', 'mproduct_molster', '**mypass**', 'mproduct_data');
   if (!$result)
     throw new Exception('Could not connect to database server');
   else
     return $result;
}

?>



whats wrong with this, im still very very new to php, i was using a book when making this script. it looks just like whats in the book
SlowWalkere
Are you running this script on friHost's servers? I think that mysqli and exceptions are new to PHP 5, but friHost is only running PHP 4.4. Because of that, either the mysqli call or the "throw new Exception" are screwing up the server and creating a parsing error.

If you're running it somewhere else, check the version of php by going to the phpinfo.php page on the server.

If that's not it, then I'm all out of ideas. Hopefully someone else knows more...

Good luck,
- Walkere
m-productions
yeah the book im using is for php 5 ..... meaning msqli is the problem... well thats not good, the main reason i came to this host was to get all my php working...... errrf

anyway... if i cant use mysqli then how do i make the script, beacuse thats how my book always does it...
hexkid
throw is not part of PHP 4. It only works for PHP 5 or greater.
You can use mysqli on PHP >= 4.1
m-productions
hexkid wrote:
throw is not part of PHP 4. It only works for PHP 5 or greater.
You can use mysqli on PHP >= 4.1



then what should i use instead of throw, this also is used in a few areas.

actully, it seems there even more php 5 based things that its using..... i duno what im gana do, i guess i need to find another host just to host my php files on... o.0
hexkid
m-productions wrote:
then what should i use instead of throw, this also is used in a few areas.
Use "standard" procedural programming insted
Code:
<?php

function db_connect()
{
   $result = new mysqli('localhost', 'mproduct_molster', '**mypass**', 'mproduct_data');
   return $result;
}

$con = db_connect();
if (!$con) {
  // with PHP5 this would have thrown an exception
  exit('Cannot connect.');
}

?>


m-productions wrote:
it seems there even more php 5 based things that its using..... i duno what im gana do, i guess i need to find another host just to host my php files on...
That might be the best alternative if you prefer to keep your code compatible with only PHP5.
Stubru Freak
I would search another host. php5 exceptions are really useful if you learn how to use them.
Related topics
Impossible parse error!
Trouble figuring out a parse error
Parse error: syntax error, unexpected '{' in /home/frih/publ
php error ?[parse error]
Parse error - need help
error
unexpected T_VARIABLE, expecting
PHP - Error
Error I can't seem to fix.
[PHP] Parse error
Parse Error in PHP I can't figure out.
e-mail error *sigh*
login and register system error
Cannot find parse error
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.