Jump to content
Killersites Forums

phptek

Member
  • Posts

    6
  • Joined

  • Last visited

Posts posted by phptek

  1. I am trying to connect to an Oracle db using ZF.

     

    I was able to connect using the following script

    --------------------------------------------------------------------------------------

    <?

     

    $tns = "(DESCRIPTION =

    (ADDRESS_LIST=(ADDRESS=(PROTOCOL = TCP)(HOST = xyzhost)(PORT = 1521)))

    (CONNECT_DATA=(SID = xyzdvl)))"; //Define TNS Connection for Oracle

     

     

    // open database connection - New

    $ora_conn = oci_connect('username', 'password', $tns);

    if (!$ora_conn) {

    trigger_error('Unable to connect to database', E_USER_ERROR);

    }

     

    ?>

    --------------------------------------------------------------------------------------------

     

    Now I am trying to connect using application.ini

    See below

    ----------------------------------------------------------------

    resources.db.adapter = PDO_OCI

    resources.db.params.host = xyzhost

    resources.db.params.username = username

    resources.db.params.password = password

    resources.db.params.dbname = xyzdvl

    -----------------------------------------------------------------

     

    For some reason it's not working in ZF.

     

    Can you help me with this?

     

    Thanks a lot.

     

    Sam

  2. do you need to set this rowset to an array? I used to do this a lot when I was learning, just because i knew arrays better than objects, but if you dont need to, I would remove the ->toArray() when your returning.

     

    When you use fetchAll() your setting yourself up to retrieve more than 1 row if the condition are met. If more than one is returned this example could produce unexpected results;

     

    As an Array():

     

    (not sure what you've assigned getUser() to, but lets say its $rows)

     

    $rows = $this>getUser($username, $password);
    
    $uname = $rows['username']; //replace 'username' with the name of your database column.
    $role = $rows['role']; //replace 'role' with whatever the column name is to get the value. 
    
    //your array contains the databse column names as the array keys and the values as your array values.  Play with var_dump($rows); and refresh to see everything contained.
    

     

    As an object / rowset (omitting the toArray();)

     

    $rows = $this>getUser($username, $password);
    
    $uname = $rows->username;//replace 'username' with the name of your database column.
    $role = $rows->role; //replace 'role' with whatever the column name is to get the value. 
    
    //leaving as a rowset you keep yourself open to doing other functions to your results, whereas as an array, you are more limited.
    

     

     

    Like I said, if your $rows has more than one result brought from the SQL query this wont work, since each result will be in its own array (multi-dimensional array). use fetchRow() instead of fetchAll() when selecting if you only want / expect one result.

    Thanks a lot. Will test it out.

  3. Hi Can you let me know how to assign values from the query below:

     

    public function getUser($username, $password)

    {

    $row = $this->fetchAll("username = '$username' AND password = '$password' AND role ='admin'");

    return $row->toArray();

    }

    getUser function will return the data in an array.

    How do I set each value from this array into each variable.

    $uname = username value from array

    $role = role value from array

     

    Thanks a lot.

  4. realized after i had some lunch that my post might have confused you since i used Zend_Registry examples

     

    Zend_Registry and Zend_Session_Namespace are different obviously. If you must use sessions then below are some examples as well.

     

    start or call your session

    $session = new Zend_Session_Namespace($name);

     

    add something to your session

    $session->index = $value;

     

    call that value somewhere else in your code

    $session = new Zend_Session_Namespace($name);
    //make sure its set
    if(!isset($session->index)){
    //set it
    } else {
    //do what ya need to with its value
    }
    

     

    Registry will be cleared with every new Bootstrap request, thus you'd need to ensure your values are setup to load into it with every request, so it may not be useful with whatever you are planning to do. I tend to use them more often than Zend_Session_Namespace however.

     

    Thank you very much J. That really helped.

  5. I can't tell you how to do it within Zend... but I can't see why you couldn't use regular PHP within Zend?

     

    session_start();

    $_SESSION['username'] = 'username'; // set session

     

    echo $_SESSION['username']; // display username

     

    If Zend has it's own unique way of handling sessions though, this may not be helpful. In that case, hopefully another user can help you out. This might also help you: http://zendgeek.blogspot.com/2009/07/zend-framework-session-usage-and.html

     

    Thank you, Ben. I am familiar with regular php syntax. I was wondering if there are some classes from which i can use some methods to set sessions in Zend framework. I will check out the link you posted as well. BTW, the videos from killerphp are what got me into Zend, and now I'm loving it.

    Thanks for all you do to the community.

    Happy Thanksgiving. - Sam

  6. Can you please post an example of setting the username of the user into a session and displaying it on the page as a greeting as "Hello username".

    Can you please use an easy way to do it using the latest zend framework in controller class?

     

    Thanks a lot.

     

    Sam

×
×
  • Create New...