SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamic site a little different!

    Hello

    I am trying to build a dynamic site which uses shockwave and php/mysql and am just wondering if anyone might have any ideas.

    Read an article on a similar thing being done with shockwave and coldfusion (http://www.director-online.com/buildArticle.cfm?id=317) and have also seen some work done with shockwave and asp, so i know this should be possible with php/mysql.

    For the moment i am just trying to connect to a mysql database

    ----------------------------------------------
    //CONNECT TO DATABASE
    $con = mysql_connect("mysql.server.com:0000",$g_dbuid,$g_dbpwd);

    if ($con==NULL)
    {
    echo("301 Couldn't connect to MySQL\n\n");
    exit(-1);
    }

    $db = mysql_select_db("database_name",$con);
    ----------------------------------------------

    using pretty standard code, but because the code is broken into many lines the shockwave does'nt like it and seems to prefer if it could send it all in one line, so thats my first problem.

    my second is, in the coldfusion (mentioned above) article it talks of calling a page that excecutes the code, i've never done this in php is it possible to put the connection code in a .php script and simply call the script from another .php code with one line?

    i'd also appreciate people letting me know if anybody knows of any articles or documentation that covers this kind of thing?


    any help would be greatly appreciated!
    Thanks in advance
    Garrett

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry that I am not answering your main question here, but does this code actually work as intended?

    if ($con==NULL)

    If it does then I am disapointed at PHP for being too flexible and forgiving. This is illogical. You cannot compare a value to NULL for equality. NULL is synonymous with "unknown" and it is impossible to compare something against something else that is of an unknown value. I'm almost sure that this will not work as intended. You are better off using the is_null() function for testing for null. http://www.php.net/manual/en/function.is-null.php

    In any case, you should also be aware that mysql_connect will return FALSE if a connection is not made:
    resource mysql_connect ([string hostname [:port] [:/path/to/socket] [, string username [, string password]]])

    Returns a MySQL link identifier on success, or FALSE on failure.
    http://www.php.net/manual/en/function.mysql-connect.php

    I think that the documentation here is lacking because I don't know what the heck data type "resource" is. I suspect that it should be "int".

    Anyway, this means that you can test for whether the connection failed like so:

    if ($con == 0)

    or even just:

    if ( ! $con )

    Regarding including code from other files, yes use the include() directive http://www.php.net/manual/en/function.include.php Read the manual for the tips and pitfalls.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello

    yes it was working but i've changed it anyway to yours.

    for testing whether the connection failed is no problem anyway in the php, but doing this in the shockwave it seems to execute but returns nothing, at least so far the shockwave doe'nt fall over which indicates what i am doing is not wrong shockwave side, just does'nt succeed in connecting.

    the thing is from shockwave you need to send a command in this format....

    result = sendnettext(http://www.asquare.org/execute.php", variable1, variable2)

    when result = 1 the script has worked, so what i need to do is figure out how i can make a php file (execute.php) which will execute when i call it.

    so at the moment i would like to be able to test all in php, having one script call the execute.php and pass it any variables it needs to work with at the same time yet include does'nt give this oportunity? is there a command like call or something that does this in php?

    garrett

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, just on the if($con == NULL) thing again, your code may well work as intended for when their is a connection in place (the normal course of events), but if you were to test it for the case that the conection was not made, I think you will find that it will not enter the if path as you intend it to. Anyway, enough.

    result = sendnettext(http://www.asquare.org/execute.php", variable1, variable2)

    If you are calling the php script through HTTP as the above suggests, then you can pass your variables in the URL using the GET method.

    eg

    http://www.asquare.org/execute.php?variable1=foo&variable2=bar

    Now from within the script execute.php you will be able to access the variables:

    $varialbe1 and $variable2


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •