Model don't save into table using Yii and php 8.1 - yii2

I migrate from PHP 7.4 to PHP 8.1 and now I have problem just with a table.
Database: 10.3.38-MariaDB
Yii version: "yiisoft/yii2": "~2.0.47",
This table structure is this:
CREATE TABLE `registro_actividad` (
`id` int(11) NOT NULL,
`usuario_id` int(11) DEFAULT NULL,
`ip` varchar(20) DEFAULT NULL,
`fecha_hora` datetime DEFAULT NULL,
`modulo` varchar(50) DEFAULT NULL,
`accion` varchar(20) DEFAULT NULL,
`nivel` varchar(10) DEFAULT NULL,
`datos` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
ALTER TABLE `registro_actividad`
ADD PRIMARY KEY (`id`),
ADD KEY `registro_actividad_FK` (`usuario_id`);
ALTER TABLE `registro_actividad`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `registro_actividad`
ADD CONSTRAINT `registro_actividad_FK` FOREIGN KEY (`usuario_id`) REFERENCES `usuario` (`id`);
The codo from controller is:
$registro = new RegistroActividad();
$registro->usuario_id =7;
$registro->ip = "127.0.1.1";
$registro->fecha_hora = "2023-02-13 17:35:53";
$registro->modulo = "ticket";
$registro->accion = "update";
$registro->datos = "hi";
$registro->nivel ="info";
if($registro->save()) {
echo "<br>Recorded successfully";
}else{
echo "<br>Error to save model: <br>";
var_dump( $registro->getErrors() );
}
When I execute just a get a void array.

There was a error on vendor, I just delete /vendor folder and execute "composer update" and it were resolved.
I'm not sure if exists some strage issue to migrate from php 7.4 to 8.1 on vendor but It worked for me.

Related

Issue with MySQL to H2 DDL

I have a table created in MySQL that is initiated and it works fine. But I have defined an in memory database with H2 for testing purposes that uses the same DDL to clone the table that I can test my app with.
CREATE TABLE `foo` (
`fieldA` BIGINT(20) NOT NULL AUTO_INCREMENT,
`fieldB` BIGINT(20) NOT NULL,
`fieldC` TIMESTAMP NOT NULL,
`fieldD` TIMESTAMP NOT NULL,
`fieldE` VARCHAR(40) NOT NULL,
`fieldF` VARCHAR(40) NOT NULL,
`fieldG` CHAR(3) NOT NULL,
PRIMARY KEY (`id`),
KEY `fieldF` (`fieldF`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
But when i try to initialise the table for my tests it spits back this error:
Caused by: org.h2.jdbc.JdbcSQLException: Unknown data type: "fieldF";
That's about as helpful as the error gets. I've explicitly set field F to VARCHAR(40), so what have do i need to do more?
if it helps, I'm creating the table in Spring Boot configuration here:
#Configuration
#EnableAutoConfiguration
#Import(ImportDataJobConfig.class)
public class TestJobConfiguration {
#Bean
public DataSource tlDataSource() {
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.setType(H2)
.setScriptEncoding("UTF-8")
.ignoreFailedDrops(true)
.addScript("sql/ve/init.sql")
.build();
}
}
Thanks!
Using h2-1.4.196 MySQL mode, your code snippet gives the following error:
Column "ID" not found (...)
Your DDL is wrong around id and needs to be fixed.
In order to fix the error you're facing, I would suggest:
Use the MySQL mode in your JDBC URL like jdbc:h2:mem:;mode=mysql
It seems your real primary key is fieldA, not id. Please change your SQL DDL accordingly:
CREATE TABLE `foo` (
`fieldA` BIGINT(20) NOT NULL AUTO_INCREMENT,
`fieldB` BIGINT(20) NOT NULL,
`fieldC` TIMESTAMP NOT NULL,
`fieldD` TIMESTAMP NOT NULL,
`fieldE` VARCHAR(40) NOT NULL,
`fieldF` VARCHAR(40) NOT NULL,
`fieldG` CHAR(3) NOT NULL,
PRIMARY KEY (`fieldA`),
KEY `fieldF` (`fieldF`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Change table structure from mysql to sqllite

i want to change database of my simple application from mysql to sqlite, this is my sql command :
CREATE TABLE `Todo` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Category` varchar(255) DEFAULT NULL,
`State` varchar(255) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
im try to create sqllite but return me this error : Error: near "AUTO_INCREMENT": syntax error how i can fix it ?
Instead of using primary key separately, please mention it with your AUTO INCREMENT key
CREATE TABLE `Todo` (
`Id` integer primary key AUTOINCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Category` varchar(255) DEFAULT NULL,
`State` varchar(255) DEFAULT NULL
)

How do i enable EER Model in MYSQL 6.3 workbench ? or How can i create foreign key for my "offers" table?

These are my tables users and offers
users
name username email password authority enabled
offers
id text
But i want to create a foreign key in my offers table from the column name "username" in my users table. How do i do it with my sql workbench 6.3 ? or how do i enable EER model for my tables ?
These are create statement for the two tables.
offer table
CREATE TABLE `offer` (
`id` int(11) NOT NULL,
`text` varchar(45) DEFAULT NULL,
`username_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `username_id_idx` (`username_id`),
CONSTRAINT `username_id` FOREIGN KEY (`username_id`) REFERENCES `user` (`iduser`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
user table
CREATE TABLE `user` (
`iduser` int(11) NOT NULL,
`username` varchar(45) DEFAULT NULL,
`email` varchar(45) DEFAULT NULL,
`password` varchar(45) DEFAULT NULL,
`authority` varchar(45) DEFAULT NULL,
`enabled` varchar(45) DEFAULT NULL,
PRIMARY KEY (`iduser`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
If you are using Workbench 6.3 you can check the EER diagram by :
Database - > Reverse Engineer - > Select a connection - > Select the scheme you want to see.
Hope this helps!

Error when importing schema.sql

I'm new to sql, currently I am using phpMyAdmin via XAMP, I think that uses mysql so correct me if I'm wrong by saying that. Anywhos, I'm trying to import a schema.sql data file into my database I created called "test" but I got an error upon importing it:
It says
Import has been successfully finished, 1 queries executed.
(schema.sql)
But then it also gives me an error message:
CREATE TABLE `population` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`location` varchar(150) NOT NULL,
`slug` varchar(150) NOT NULL,
`population` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL said: Documentation
1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
and :
Notice in .\import.php#704 Undefined variable: import_text Backtrace
I'm not sure what the issue is. The database I created is completely and has nothing in it.
Column id is the auto-column in question; auto-columns need to be defined as a key, for example as a unique key or a primary key. In your case, a primary key is a good idea because - well, it's your id-column.
CREATE TABLE `population` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`location` varchar(150) NOT NULL,
`slug` varchar(150) NOT NULL,
`population` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Create MySQL Tables with Ansible

I'm using ansible to manage a small mail server using ubuntu. I wanted to use ansible to create a database which I can do and also create users for the database(s) which I can do also. But I'm not sure how to create tables using ansible. I'm trying to create the following three MySQL tables using ansible:
1)
CREATE TABLE `virtual_domains` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2)
CREATE TABLE `virtual_users` (
`id` int(11) NOT NULL auto_increment,
`domain_id` int(11) NOT NULL,
`password` varchar(106) NOT NULL,
`email` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3)
CREATE TABLE `virtual_aliases` (
`id` int(11) NOT NULL auto_increment,
`domain_id` int(11) NOT NULL,
`source` varchar(100) NOT NULL,
`destination` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I have searched and searched and even ask in #ansible and have stated that I can use the mysql_db module to complete the above task but I can't find any examples that will give me some type of direction on how to achieve the above in ansible.
Any and all help would be GREATLY appreciated!
With the mysql_db module you can import a MySQL file. So you can simply copy all 3 create statements into one singly text file and import it like this:
- mysql_db: name=my_db state=import target=/tmp/dump.sql.bz2
That example is taken from the above linked docs page, there are more tasks including one which shows you how to copy the file to the host before.
hosts: mysql
tasks:
name: create a table in mysql_databases
command: mysql -u root -p[root1234] testdb --skip-column-names --execute "create table test_table (Name varchar(255), EmpID INT NOT NULL)"