Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access WAMPSQL database from tomcat page via different port

    Hi all, first time post here.

    I have setup a wampsql database on my server on port 80 and I can pull data from the database using the PHP area within WAMP (c:\wamp\www\). I successfully accessed the database with the following code:

    $con = mysql_connect("localhost","myusername","mypassword");
    if (!$con)
    **{
    **die('Could not connect: ' . mysql_error());
    **}

    I am developing a web page that requires JavaScript so I have setup tomcat environement using a different port and installed Javabridge to give me PHP capability within tomcat.

    My problem is if I reuse the above code it cannot see the swampsql database from my websites on tomcat. Is there a further information I can add to the following line so I can access the wampsql db from tomcat.:

    $con = mysql_connect("localhost","myusername","mypassword"); ??

    Any help much appreciated

    Cheers

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Javascript doesn't require tomcat as its a client language, not a server one. JSP and servlets requires tomcat, but if you aren't using JSP then I wouldn't bother with the expense of the tomcat.
    What's the error you receive? If it fails, it will trigger that die. If there is no error, you need to issue a mysql_select_db() function call to choose the db to work with after the connection call.

  • #3
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply. I think I need jsp as creating a dynamic webpage.

    The error I receive is :

    "PHP fatal error: call to undefined function mysql_connect()"

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    PHP is capable of creating dynamic webpages. You don't need JSP for that unless you plan on using Java as your server side language.

    You do not have the mysql library installed. Try using the mysqli or pdo library instead:
    PHP Code:
    $con = new MySQLi('host''user''password''database');
    if (
    $con->connect_error)
    {
        
    printf('Connection error: %s'$con->connect_error);
    }

    // or
    $dsn 'mysql:dbname=testdb;host=127.0.0.1';
    $user 'user';
    $password 'pass';
    try
    {
        
    $con = new PDO($dsn$user$password);
    }
    catch (
    PDOException $ex)
    {
        
    printf('Error: %s'$ex->getMessage());

    Dormlich is the PDO expert here if you go that route.


  •  

    Posting Permissions

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