hi there,
I'm currently converting a MySQL application to PostgreSQL, and I
hacked this app to support PEAR::Db .
after some good coding days, I've found a problem: mysql_insert_id on
pear::db .
I've those two piece of code, the first is part of a class:
---------
function connect($layer, $host,$db_port, $db_name,$user, $pass) {
$dsn = "$layer://$user:$pass@$ho st:$db_port/$db_name";
$this->db_connect = DB::Connect($ds n);
return $this->db_connect;
}
function genId($sequence , $onDemand='true ') {
return $this->db_connect->nextId($sequen ce);
}
function insert_id() {
$result = $this->db_connect->nextId();
return $result;
}
---------
please note, those are the functions before my hacks:
---------
// query should be rewritten to include this; || this is not a
comments of mine
function genId($sequence ) {
return 0;
}
function insert_id() {
$result = mysql_insert_id ($this->db_connect);
return $result;
}
and here we go with code:
---------
function store() {
global $db;
if ( !$this->isCleaned() ) {
if ( !$this->cleanVars() ) {
return false;
}
}
foreach ( $this->cleanVars as $k=>$v ) {
$$k = $v;
}
if ( empty($uid) ) {
$uid = $db->genId(persone_ uid_seq"); //<<<<< this is the problem
$sql = "INSERT INTO persone
(identificativo ,nome_persona,a cronimo,passwor d,level,theme,l ast_login)
VALUES
($uid,'$uname', '$name','$pass' ,'$level','$the me',0)";
} else {
$sql ="UPDATE persone SET acronimo='$unam e', nome_persona='$ name',
password='$pass ', theme='$theme' WHERE identificativo= $uid";
}
if ( !$result = $db->query($sql) ) {
$this->setErrors("Cou ld not store data in database.");
//pretty useless because of PEAR::db error handling
return false;
}
if ( empty($uid) ) {
$uid = $db->insert_id(); //<<<<maybe this?
}
return $uid;
}
---------
my problem is that I had to define two identical functions to make the
app working, the second is that in database the id generated starts
from zero.
I've an alredy populated database, so these values cannot be inserted,
I need generated IDs that start from a point, in mysql those functions
works without problems.
Things I don't understand:
have PEAR::db something that could replace the above function? in the
source code I've seen something similar to createsequence but I'm not
sure how to use it.
second, what is $uid = $db->genId(persone_ uid_seq"); ? persone is a
table of mines, but persone_uid_seq not.
surely I'm missing something important with the sequences, can you
please tell me what's wrong? thanks.
kain 0 2399 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Analysis&Solutions |
last post by:
Greetings:
Crack open the beer, PEAR DB 1.6.0 is here! (Hey, I'm a bit giddy
with excitement that my intense work during the past seven weeks
has come to fruition.)
For those unfamiliar with PEAR DB, it's a package of PHP classes
that provide an object oriented API with common methods of accessing
thirteen of PHP's database driver extensions:
dBase, FrontBase, InterBase, Informix, mSQL, MS SQL Server,
|
by: Wayne Smallman |
last post by:
Hi! I've had a look through various forums for some advice on getting
Pear DB working with my Entropy installation of PHP Version 4.3.6
Most of the topics I found are after the fact, so that's not much use to me.
I want run Pear DB under PHP Version 4.3.6 with MySQL Version 3.23.49.
At the minute, I'm getting this error from the Pear.php file:
Code:
|
by: James |
last post by:
Hey everyone, I have a really obscure but impassable problem with a
reasonably simple piece of php/PEAR DB/MySQL code
When calling several stored procs the first call succeeds, but
subsequent calls fail no matter which SP is called first it always
works, and the rest fail... with:
>>>
|
by: lawrence k |
last post by:
I wrote a simple CMS for personal use. I'm thinking of using it for
other clients now. It's use of the database is slow and inefficient.
I'm thinking of switching to the PEAR class listed here:
http://pear.php.net/package/DB
What do people think of it?
|
by: Paul |
last post by:
I recently upgraded from MySQL 3.23 to 4.1. Now db is not working properly.
I'd very much like your help in solving this issue!
Here's the code I used to test it:
require_once 'DB.php';
$db =&
DB::connect('mysql://user:password@localhost/dbname');
if (PEAR::isError($db)) {
die($db->getMessage());
| |
by: Paul |
last post by:
I have tested my logic flow and determined that the conversion from what is
given to the
$db->prepare() statement and what is stored in the database iteslf goes
from:
"I'm helpful"
to
"I'm helpful"
is converted by pear's DB. I am using $db->prepare() statement. When I do
|
by: mpar612 |
last post by:
I am stumped. Below is my code and it doesn't work (I removed the
$login info for posting).
PHP Code:
require 'PEAR/DB.php';
// Connect to the database
$db = DB::connect($login);
if (DB::isError($db)) { die ("Can't connect: " . $db->getMessage()); }
|
by: jmark |
last post by:
I need some assistance on how to create a select statement using PEAR
DB or MySQL with the LIKE function.
That is I am looking of how I can get statement like this work.
SELECT * FROM customer WHERE name LIKE '%?'
|
by: daralthus |
last post by:
Hello!
I would like to ask your help, i have founded a great code here: http://www.jamescaws.co.uk/2008/07/dynamically-count-exit-link-clicks-throughs-using-javascript-php/
but it uses Pear DB for the database connection. the problem is that it don't works, actually the php don't writes anything in the table and i don't get any error when i add the if (PEAR::isError($db)) {
die($db->getMessage());} code, so not the connection...
Then i...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |