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 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Database connection ...?

    Hi all,

    i have just installed php/mysql (which is working) on my linux box .The problem is, i don't seem to be able to get rows from the database.

    PHP Code:

    require_once('DB.php');

    $dB=DB::connect("mysql://localhost/test");

    if(
    DB::iserror())
        die(
    $dB->getMessage());
    else
        echo(
    "Connected !!!");  //<----- prints connected :) 

    $result=$dB->execute("insert into Music values(1987,\"DDD\",23)");
    echo(
    "Executed");   // <-- does not appear   :confused: 
    Can anyone help me ?

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    You are missing some braces


    PHP Code:
    if(DB::iserror()) {
        die(
    $dB->getMessage()); 
    } else {
        echo 
    "Connected !!!";  //<----- prints connected :) 


  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi ,

    i get this error :

    Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    .

    The wierd thing is that i can connect to mysql in my java programs etc.




    mysqladmin status
    Uptime: 1791 Threads: 1 Questions: 5 Slow queries: 0 Opens: 6 Flush tables: 1 Open tables: 0 Queries per second avg: 0.003
    also,
    mysqladmin ping
    mysqld is alive
    So, i am guessing i have to edit something to get it working.

    ps i am running Slackware 9.0 , default mysql installation.

    the phpinfo(); gives this:

    Active Persistent Links 0
    Active Links 0
    Client API version 3.23.49
    MYSQL_MODULE_TYPE builtin
    MYSQL_SOCKET /tmp/mysql.sock
    MYSQL_INCLUDE no value
    MYSQL_LIBS no value

    Any help would be appreciated .

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    PEAR::execute() is used when passing a prepared() statement , for a simple query use query()

    PHP Code:
    <?
    require_once('DB.php');
    $dB=DB::connect("mysql://localhost/test");
    if(
    DB::iserror()){
        die(
    $dB->getMessage());
    }else{
        echo(
    "Connected !!!");
    }
    $sql='insert into Music values(1987,"DDD",23)';
    $result $dB->query($sql);
    ?>
    & check the result !
    <?
    if (DB::isError($result)) {
            die (
    $result->getMessage());
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still, can't connect.

    If i edit the php.ini file , it is supposed to change when i call phpinfo(); right ?

    Currently i have :


    Directive Local Value Master Value
    mysql.allow_persistent On On
    mysql.connect_timeout 60 60
    mysql.default_host no value no value
    mysql.default_password no value no value
    mysql.default_port no value no value

    mysql.default_socket no value no value <-but i already changed it to /var/run/mysql/mysql.sock

    mysql.default_user no value no value
    mysql.max_links Unlimited Unlimited
    mysql.max_persistent Unlimited Unlimited
    mysql.trace_mode Off Off


    Could someone post their php.ini here ?


    Thanks.

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    doh , totally missed the connection problem post ~
    on my fedora install the default port,socket,host and user are all blank but it all still works

    check what your mysql configuration says (check path)..

    `cat /etc/my.cnf | grep socket`

    also note that if you made changes to php.ini you need to restart apache (if PHP is an apache module) before the changes will be implemented.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #7
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,
    in my /etc/ i have :



    my-huge.cnf
    my-medium.cnf
    my-small.cnf

    but no my.cnf.

    cat my-small.cnf gives:



    # Example mysql config file for small systems.
    #
    # This is for a system with little memory (<= 64M) where MySQL is only used
    # from time to time and it's important that the mysqld deamon
    # doesn't use much resources.
    #
    # You can copy this file to
    # /etc/my.cnf to set global options,
    # mysql-data-dir/my.cnf to set server-specific options (in this
    # installation this directory is /var/lib/mysql) or
    # ~/.my.cnf to set user-specific options.
    #
    # One can in this file use all long options that the program supports.
    # If you want to know which options a program support, run the program
    # with --help option.

    # The following options will be passed to all MySQL clients
    [client]
    #password = your_password
    port = 3306
    socket = /var/run/mysql/mysql.sock

    # Here follows entries for some specific programs

    # The MySQL server
    [mysqld]
    port = 3306
    socket = /var/run/mysql/mysql.sock
    skip-locking
    set-variable = key_buffer=16K
    set-variable = max_allowed_packet=1M
    set-variable = thread_stack=64K
    set-variable = table_cache=4
    set-variable = sort_buffer=64K
    set-variable = net_buffer_length=2K
    server-id = 1

    # Uncomment the following if you want to log updates
    #log-bin

    # Uncomment the following if you are NOT using BDB tables
    #skip-bdb

    # Uncomment the following if you are using InnoDB tables
    #innodb_data_home_dir = /var/lib/mysql/
    #innodb_data_file_path = ibdata1:10M:autoextend
    #innodb_log_group_home_dir = /var/lib/mysql/
    #innodb_log_arch_dir = /var/lib/mysql/
    # You can set .._buffer_pool_size up to 50 - 80 %
    # of RAM but beware of setting memory usage too high
    #set-variable = innodb_buffer_pool_size=16M
    #set-variable = innodb_additional_mem_pool_size=2M
    # Set .._log_file_size to 25 % of buffer pool size
    #set-variable = innodb_log_file_size=5M
    #set-variable = innodb_log_buffer_size=8M
    #innodb_flush_log_at_trx_commit=1
    #set-variable = innodb_lock_wait_timeout=50

    [mysqldump]
    quick
    set-variable = max_allowed_packet=16M

    [mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates

    [isamchk]
    set-variable = key_buffer=8M
    set-variable = sort_buffer=8M

    [myisamchk]
    set-variable = key_buffer=8M
    set-variable = sort_buffer=8M

    [mysqlhotcopy]
    Any help ?

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    ok, try copying say /etc/my-small.cnf to /etc/my.cnf (as is) and restarting everything (mysql & apache), + check that your php.ini mysql.default_socket matches that in the my.cnf (or leave it blank)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey, it's me again.I have tried lots of stuff but cant get it working.What the yakk-snarf does it need ?Where does mysql read the socket ,host etc stuff from ?

    I am going insane .
    Last edited by firepages; 05-03-2004 at 12:01 PM.

  • #10
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    lol , sorry to laugh but I having similar issues with firebird .. everything & dog can talk to it but PHP

    but err , if PHP and MySQL both claim to be using the same socket (& port (3306)) & mysql is running then I dont see why it won't work , MySQL should look first in /etc/my.cnf for its configuration , have you done a `locate my.cnf` ? to see if there are any others about ? also did you
    configure php --with-mysql=/path/to/mysql
    ? or let it use the defaults?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #11
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey!I am at uni right now but i will try "locate my.cnf" later.As for the --config, no i did not use the with-mysql option(the reason being i did not compile it[mysql] from the source.I assumed that if i don't put the path to the source then it's the same as not puttinng it at all.Am i wrong?).

    BTW i just noticed that you are from Australia, i am in NZ :-).

  • #12
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #13
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, i have got it working :-) .The solution was very simple indeed.What i did was i just created a symbolic link to /var/run/mysql/mysql.sock ( ln -s /var/run/mysql/mysql.sock /tmp/mysql.sock ).


    Anyone can advise good php books(ebooks) ?


    BTW thanks to the moderator .


  •  

    Posting Permissions

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