Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

php code

Name: Anonymous 2007-08-01 19:16 ID:Ge7BfjLz

Here is a code snippet from my project
$db = mysql_pconnect('', 'name', 'pass');
$sd=  mysql_select_db("books",$db);

the first part works perfectly and it connects to the mysql
however it will not choose the database i need.

Name: Anonymous 2007-08-01 19:24 ID:GH4aauor

too bad

Name: Anonymous 2007-08-01 19:29 ID:Heaven

forced troll is forced

Name: Anonymous 2007-08-01 19:56 ID:Ge7BfjLz

so what have i done wrong?

Name: Anonymous 2007-08-01 20:10 ID:fPxsh+tI

>>4
Everything. Your entire life up to and including this point is a failure.

Name: Anonymous 2007-08-01 20:30 ID:SoiA2EAj

ok, but specifically what is the mistake in that line of code

Name: Anonymous 2007-08-01 20:34 ID:RYIRZjIA

s/(sel.+\()([^,]+),(.+)(\).+$(/\1\3,\2\4/

Name: Anonymous 2007-08-01 20:42 ID:O2B6vtO9

>>6

How do you know that mysql_pconnect succeeded?

Name: Anonymous 2007-08-01 20:49 ID:SoiA2EAj

when i first tested it i had
  if (!$db)
  {
     echo 'Error: Could not connect to database.  Please try again later.';
     exit;
  }
after it, so i'm pretty sure it worked unless i did that bit wrong

Name: Anonymous 2007-08-01 20:50 ID:O2B6vtO9

Ok, and does mysql_select_db return TRUE or FALSE?

Name: Anonymous 2007-08-01 20:54 ID:SoiA2EAj

false

Name: Anonymous 2007-08-01 21:01 ID:O2B6vtO9

Ok, then use mysql_error to see why.

Name: Anonymous 2007-08-01 21:13 ID:SoiA2EAj

it's blank if i've used it right
  $sd=  mysql_select_db("nuclear_books",$db);
  echo mysql_error();
  if ($sd = "false")
  {
    echo "selecting database failed <br>";
  }
It displays selecting database failed but mysql_error isn't returning anything

Name: Anonymous 2007-08-01 21:20 ID:O2B6vtO9

>>13
That's because mysql_select_db is not failing. Instead of the incorrect if($sd = "false"), try if(!$sd).

Name: Anonymous 2007-08-01 21:22 ID:O2B6vtO9

Name: Anonymous 2007-08-01 21:31 ID:SoiA2EAj

if i change the name of the database to something random i get
 
Access denied for user 'user'@'localhost' to database 'dhjfjh_books'
selecting database failed

It seems to think it selected the database properly but still returns false

Name: Anonymous 2007-08-01 21:32 ID:Jgy2tx7g

boolean != string

Name: Anonymous 2007-08-01 21:35 ID:O2B6vtO9

>>16

Did you read the pages I posted in >>15? Here is where you fail it:

- using the = assignment operator instead of the == comparison operator in ($sd = "false"). This will return the value "false" to the if statement.

- using the string "false" instead of the boolean constant FALSE. In fact, "false" evaluates to TRUE.

Name: Anonymous 2007-08-01 21:39 ID:O2B6vtO9

It's probably worth pointing out that if you have:

if (expr) {
  lolwhat();
}

then lolwhat() is only executed if expr evaluates to boolean TRUE.

And instead of testing the expression $sd == FALSE you can use the negation operator ! and test !$sd because it turns TRUE into FALSE and FALSE into TRUE.

Name: Anonymous 2007-08-01 21:40 ID:Kp8tClKP

DON'T HELP HIM

he is complete failure

Name: Anonymous 2007-08-01 21:42 ID:SoiA2EAj

thanks i've been trying to work this out for 2 days, you're a life saver

Name: Anonymous 2007-08-01 21:44 ID:SoiA2EAj

yes i am a failure, which is why i'm asking for help so i can try to defail myself
and it didn't upload properly so i didn't see those when i posted 16 sorry

Name: Anonymous 2007-08-01 21:46 ID:x0DU4fmF

>>22
Defail yourself? Ain't gonna happen. BE AN HERO NOW.

Name: Anonymous 2007-08-01 21:49 ID:SoiA2EAj

meh i said try to, i can live with being a failure, i'm still happy

Name: Anonymous 2007-08-01 21:49 ID:Kp8tClKP

defail is the most amusing verb i've encountered all day

Name: Anonymous 2007-08-02 0:40 ID:lOqtG6ri

  $sd=  mysql_select_db("nuclear_books",$db);
  echo mysql_error();
  if ($sd = "false")
  {
    echo "selecting database failed <br>";
  }

mysql_select_db('nuclear_books',$db) or print(mysql_error().'<br />Failed to select the database.');

That's the EXPERT PROGRAMMER way of writing the above.

Name: Anonymous 2007-08-02 5:31 ID:Ioxtf6W6

>>1
How do I reached max connections with persistancy?

Name: Anonymous 2007-08-02 5:33 ID:Ioxtf6W6

Try a test first:

@mysql_pconnect("localhost", "username", "password") or die(mysql_error());
@mysql_select_db("books") or die(mysql_error());

And see what goes wrong.

Name: Anonymous 2007-08-02 16:18 ID:/B+hlxrk

>>28
@ considered harmful

Name: Anonymous 2007-08-02 18:12 ID:Ioxtf6W6

>>29
You think I would give good advice?

Name: Anonymous 2009-03-06 7:23


error message upon failure.

Name: Anonymous 2009-03-06 10:06

Posting small amounts of  of text you  Editorian an essential  essential Island to  to all the  other car models  And then The  blame the language  language for our  x86 processors In  In order to  to carry out  out on rotating  some trippy shit.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List